package com.vo;

import com.common.utils.DateUtil;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class MsgTask implements  Runnable , Delayed {

    private long excuteTime;

    private String msg;

    public MsgTask(String msg,long excuteTime){
        this.msg=msg;
        this.excuteTime=TimeUnit.NANOSECONDS.convert(excuteTime, TimeUnit.MILLISECONDS)+System.nanoTime();
    }

    @Override
    public void run() {
        System.out.println(msg+"__"+ DateUtil.getDate_yyyyMMddHHSS());
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert(this.excuteTime- System.nanoTime() , TimeUnit.NANOSECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        MsgTask msg = (MsgTask)o;
        return this.excuteTime>msg.excuteTime?1:( this.excuteTime<msg.excuteTime?-1:0);
    }
}
